package generic;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: cjj
 * @Date: 2025/4/29
 * Feeder 类
 */
public class Feeder {
    public static void main(String[] args) {
        Feeder feeder =  new Feeder();
        List<Animal> list=new ArrayList<>();
        list.add(new Dog());
        list.add(new Cat());


        ArrayList<Dog> dogs = new ArrayList<>();
        dogs.add(new Dog());
        feeder.feed(dogs);

    }

    /**
     * 饲养的方法
     * 类型必须是Animal的子类型
     * 要么是Animal本身
     * ?通配符
     * 泛型的上限
     * @param animals
     */
    public void feed(List<? extends Dog> animals){
        for (Animal animal : animals) {
            animal.eat();
        }
    }

    /**
     * 泛型的下限
     * Animal或者Animal的父类型
     * @param animals
     */
    public void method1(List<? super Animal>animals){
        for (Object animal : animals) {
            
        }
    }
}
